//按奇偶排序数组
class Solution {
public:
    vector<int> sortArrayByParity(vector<int>& nums) {
     int cur = 0, prev = -1;
     while(cur < nums.size())
     {
        if(nums[cur] % 2 == 0)
        {
            swap(nums[++prev], nums[cur]);
        }
        ++cur;
     }   
     return nums;
    }
};


//找到字符串中所有字母异位词
class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        int n = s.size(), m = p.size();
        if(n < m) return {};
        int hash[26] = {0};
        for(char ch : p)
            hash[ch - 'a']--;

        vector<int> ret;
        int left = 0, right = 0;
        for(; right < n; right++)
        {
            int in = s[right] - 'a';
            hash[in]++;
            while(hash[in] > 0)
                --hash[s[left++] - 'a'];
            
            if(right - left + 1 == m)
                ret.push_back(left);
        }
        return ret;
    }
};
